package net.dipper.tankwar.game.control;

import net.dipper.tankwar.core.data.ObjectMap;
import net.dipper.tankwar.game.ui.GameContext;
import wnb.util.control.Command;
import wnb.util.control.CommandEngine;
import wnb.util.control.SleepCommand;

public class GameRuleCommand extends Command {
	private static final long DEFAULT_DELAY = 50;
	
	private GameContext context;
	private ObjectMap map;
	private CommandEngine engine;
	private SleepCommand sleepCommand;
	private RunBulletCommand runBulletCommand;
	private RunUnitCommand runUnitCommand;
	private CalcResultCommand calcResultCommand;

	public GameRuleCommand(GameContext context, ObjectMap map, CommandEngine engine){
		this.context = context;
		this.map = map;
		this.engine = engine;
		this.sleepCommand = new SleepCommand(engine, this, DEFAULT_DELAY);
		this.runBulletCommand = new RunBulletCommand(this.map);
		this.runUnitCommand = new RunUnitCommand(this.map);
		this.calcResultCommand = new CalcResultCommand(this.context, this.map);
	}

	@Override
	public void exec() {
		this.sleepCommand.refreshStartTime();
		this.engine.addCommand(runBulletCommand);
		this.engine.addCommand(runUnitCommand);
		this.engine.addCommand(calcResultCommand);
		this.engine.addCommand(sleepCommand);
	}

}
